<?php
namespace app\serverfund\logic;

use \app\manage\logic\BaseLogic;
use \app\manage\service\ApiBase;

class CurrencyAccount extends BaseLogic
{
    protected $currencyAccountValidate = '\app\serverfund\validate\CurrencyAccount';
    protected $currencyAccountLogic = '\app\serverfund\logic\CurrencyAccount';

    use \app\serveruser\traits\RunOneAddUserInfo;
    use \app\serveruser\traits\AddAppIdToRunOne;

    
    //获取用户的资金分页列表
    public function list($data): array 
    {
        return $this->_runOneAddLotsUserInfo($data, 'serverfund/currency/CurrencyAccount/list', $this->currencyAccountValidate, $this->currencyAccountLogic);
    }
    // 某user_ids的用户资金列表
    public function listByUserIds($data): array 
    {
        return $this->_runOneAddLotsUserInfo($data, 'serverfund/currency/CurrencyAccount/listByUserIds', $this->currencyAccountValidate, $this->currencyAccountLogic);
    }

    //解冻 a
    public function unfreeze($data): array 
    {
        //基本信息的获取
        $app_key = ApiBase::getAppKey();
        $getBase['query'] = json_encode([
            ['path'=>'serveruser/auth/Token/hGetAll', 'param'=>['token'=>$data['token']]],
            ['path'=>'serveruser/auth/App/find', 'param'=>['app_key'=>$app_key]],
            ['path'=>'serveruser/user/User/infoAll', 'param'=>['id'=>$data['user_id']]]
        ]);
        $baseInfo =  ApiBase::sendDataLots(config('proxy_all_url'), $getBase);
        if($baseInfo['status'] != SUCCESS_STATUS){
            return $baseInfo;
        }
        $data['app_id'] = $baseInfo['res'][1]['id'];
        $data['update_ip'] = request()->ip();
        $data['type'] = 'system';
        $data['freeze_counts'] = 1;
        $data['opposite_id'] = $baseInfo['res'][0]['id'];
        $data['opposite_info'] = $baseInfo['res'][0];
        $data['user_info'] = $baseInfo['res'][2];
        $unfreezeQuery['query'] = json_encode([
            ['path'=>'serverfund/currency/CurrencyAccount/unfreeze', 'param'=>$data]
        ]);
        return ApiBase::sendDataOne(config('proxy_all_url'), $unfreezeQuery);
    }

    //冻结 a
    public function freeze($data): array 
    {
        /*获取基本信息*/
        $app_key = ApiBase::getAppKey();
        $data['update_ip'] = request()->ip();
        $data['opposite_id'] = SYSTEM_ID;
        $ids = $data['user_id'] . ',' . $data['opposite_id'];
        $getBaseInfo['query'] = json_encode([
            ["path"=>"serveruser/user/User/infoByIds","param"=>['ids'=>$ids]],
            ["path"=>"serveruser/auth/App/find","param"=>['app_key'=>$app_key]]
        ]);
        $baseInfo = ApiBase::sendDataLots(config('proxy_all_url'), $getBaseInfo);
        if($baseInfo['status'] != SUCCESS_STATUS){
            return $baseInfo;
        }
        $data['app_id'] = $baseInfo['res'][1]['id'];
        $data['user_info'] = $baseInfo['res'][0][0];
        $data['opposite_info'] = $baseInfo['res'][0][1];
        $freezeQuery['query'] = json_encode([
            ['path'=>'serverfund/currency/CurrencyAccount/adminFreeze', 'param'=>$data]
        ]);
        return ApiBase::sendDataOne(config('proxy_all_url'), $freezeQuery);
    }

    //系统充值
    public function prepaid($data): array 
    {
        return $this->_addAppIdToRunOne($data, 'serverfund/currency/CurrencyAccount/prepaid', $this->currencyAccountValidate, $this->currencyAccountLogic);
    }

    //兑换
    public function exchange($data): array 
    {
        return $this->_addAppIdToRunOne($data, 'serverfund/currency/CurrencyAccount/exchange', $this->currencyAccountValidate, $this->currencyAccountLogic);
    }


}